//
//  NYExamineStartTestCell.m
//  NiuWaJiaoYu
//
//  Created by 袁航 on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYExamineStartTestCell.h"
@interface NYExamineStartTestCell ()
@property(nonatomic, strong) TTTAttributedLabel *titleLabel;
@property(nonatomic, strong) TTTAttributedLabel *detailLabel;
@property(nonatomic, strong) TTTAttributedLabel *timeLabel;
@end
@implementation NYExamineStartTestCell
- (BOOL)shouldUpdateCellWithObject:(id)object
{
        self.startTestModel = object;
        return YES;
}
- (void)setStartTestModel:(NYExamineStartTestModel *)startTestModel
{
        _startTestModel = startTestModel;
        [self updateContent];
}
- (void)updateContent
{
        [super updateContent];
        
        NSAttributedString *attr = [[NSAttributedString alloc] initWithData:[NOT_NULL_STRING_DEFAULT_EMPTY(self.startTestModel.ex_title) dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        self.titleLabel.attributedText = attr;
        
        attr = [[NSAttributedString alloc] initWithData:[NOT_NULL_STRING_DEFAULT_EMPTY(self.startTestModel.ex_desc) dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        self.detailLabel.attributedText = attr;
        
        self.timeLabel.attributedText = [self getTimeAttrString];
        
}
- (NSAttributedString *)getTimeAttrString
{
        NSDictionary *norAttr = @{
                                  NSFontAttributeName : WGSystem14Font,
                                  NSForegroundColorAttributeName : UIColorHex(0x999999)
                                  };
        NSDictionary *selAttr = @{
                                  NSFontAttributeName : WGSystem14Font,
                                  NSForegroundColorAttributeName : UIColorHex(0xFA8D00)
                                  };
        NSMutableAttributedString *attrM = [[NSMutableAttributedString alloc] initWithString:@"共计" attributes:norAttr];
        [attrM appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",(int)self.startTestModel.questions_number.integerValue] attributes:selAttr]];
        [attrM appendAttributedString:[[NSAttributedString alloc] initWithString:@"题，考试时间" attributes:norAttr]];
        [attrM appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",(int)self.startTestModel.ex_usedtime.integerValue] attributes:selAttr]];
        [attrM appendAttributedString:[[NSAttributedString alloc] initWithString:@"分钟" attributes:norAttr]];
        return attrM;
}
- (void)setupView
{
        [super setupView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.detailLabel];
        [self.contentView addSubview:self.timeLabel];
        
        [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.contentView).offset(__WGHeight(25));
                make.centerX.equalTo(self.contentView);
                make.left.equalTo(self.contentView).offset(__WGWidth(17));
                make.right.equalTo(self.contentView).offset(-__WGWidth(17));
        }];
        [self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.titleLabel.mas_bottom).offset(__WGHeight(23));
                make.left.equalTo(self.contentView).offset(__WGWidth(17));
                make.right.equalTo(self.contentView).offset(-__WGWidth(17));
        }];
        [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.detailLabel.mas_bottom).offset(__WGHeight(41));
                make.left.equalTo(self.contentView).offset(__WGWidth(32));
                make.right.equalTo(self.contentView).offset(-__WGWidth(32));
                make.height.mas_equalTo(__WGHeight(41));
                make.bottom.equalTo(self.contentView.mas_bottom).offset(-__WGHeight(43));
        }];
}
- (TTTAttributedLabel *)titleLabel
{
        if ( _titleLabel == nil )
        {
                _titleLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _titleLabel.font = WGSystem18Font;
                _titleLabel.textColor = UIColorHex(0x333333);
                _titleLabel.textAlignment = NSTextAlignmentCenter;
        }
        return _titleLabel;
}

- (TTTAttributedLabel *)detailLabel
{
        if ( _detailLabel == nil )
        {
                _detailLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _detailLabel.font = WGSystem14Font;
                _detailLabel.textColor = UIColorHex(0x666666);
                _detailLabel.numberOfLines = 0;
                _detailLabel.textAlignment = NSTextAlignmentCenter;
                
        }
        return _detailLabel;
}

- (TTTAttributedLabel *)timeLabel
{
        if ( _timeLabel == nil )
        {
                _timeLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _timeLabel.font = WGSystem14Font;
                _timeLabel.textColor = UIColorHex(0x666666);
                _timeLabel.backgroundColor = UIColorForBackground;
                _timeLabel.layer.cornerRadius = 20;
                _timeLabel.clipsToBounds = YES;
                _timeLabel.textAlignment = NSTextAlignmentCenter;
                
        }
        return _timeLabel;
}
@end
